home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / yahoo / yahooprofile.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  4KB  |  78 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. from util import callsback, threaded, pythonize, do, soupify, traceguard, odict, scrape_clean
  6. from util.BeautifulSoup import BeautifulStoneSoup
  7. from itertools import izip
  8. from logging import getLogger
  9. log = getLogger('yahooprofile')
  10. from threading import Thread
  11. import wx
  12. from urllib2 import urlopen
  13. profile_url = 'http://profiles.yahoo.com/%s?warn=1'
  14.  
  15. def get(yahooid):
  16.     data = urlopen(profile_url % yahooid).read().decode('utf-8')
  17.     return scrape_profile(data)
  18.  
  19. get = threaded(get)
  20.  
  21. def scrape_profile(s):
  22.     s = s.replace(u' ', u' ').replace(u'Hobbies:</dd>', u'Hobbies:</dt>')
  23.     soup = BeautifulStoneSoup(s, convertEntities = BeautifulStoneSoup.ALL_ENTITIES, fromEncoding = 'utf-8')
  24.     profile = odict()
  25.     for section in ('basics', 'more'):
  26.         div = soup('div', id = 'ypfl-' + section)[0].dl
  27.         if div is not None:
  28.             info = _[1]
  29.             profile.update(dictfrompairs(info))
  30.             continue
  31.         []
  32.     
  33.     links = [](_[2])
  34.     linktuples = _[3]
  35.     finallinks = []
  36.     for i, tuple in enumerate(linktuples):
  37.         finallinks.append(tuple)
  38.         if i != len(linktuples) - 1:
  39.             finallinks.append(u'\n')
  40.             continue
  41.         []
  42.     
  43.     links['Links:'] = finallinks
  44.     (do,)((lambda .0: for k in .0:
  45. if k.startswith('Cool Link'):
  46. links.pop(k)continue)(links.keys()))
  47.     profile.update(links)
  48.     for p in soup.findAll('p', attrs = {
  49.         'class': 'footnote' }):
  50.         c = p.renderContents(None)
  51.         for hdr in ('Member Since ', 'Last Update: '):
  52.             if c.startswith(hdr):
  53.                 profile[hdr] = c[len(hdr):]
  54.                 continue
  55.             []
  56.         
  57.     
  58.     for k, v in dict(profile).iteritems():
  59.         if isinstance(v, basestring):
  60.             [] if 'Home Page:' in links else dictfrompairs(dict.__setitem__, profile, k if v.strip() in ('', 'No Answer') else scrape_clean(v))
  61.             continue
  62.     
  63.     profile.pop('Yahoo! ID:', None)
  64.     return profile
  65.  
  66.  
  67. def dictfrompairs(info):
  68.     return dict(izip(info[::2], info[1::2]))
  69.  
  70.  
  71. def anchor2tuple(s):
  72.     if not s:
  73.         return None
  74.     
  75.     a = soupify(s).a
  76.     return None if a else None
  77.  
  78.